Making Async Code Run Faster in Csharp

元数据

作者: Nick Chapsas
标题: Making Async Code Run Faster in C#
分类: #async #nickchapsas
地址: https://www.youtube.com/watch?v=gW19LaAYczI

笔记

if this has thrown an exception shouldhave an aggregate exception 跳转

如果直接使用 await Task.WhenAll(tasks) 当运行时存在异常,只会输出哪一个任务异常了,而具体的异常内容却被吞掉了

public class TaskEx
{
	public static async Task<IEnumerable<T>> WhenAll<T>(params Task<T>[] tasks)
	{
		var all_tasks = Task.WhenAll(tasks);
		try
		{
			return await all_tasks;
		}
		catch(Exception)
		{
			// ignore
		}
		return all_task.Exception;
	}
}